package leecode

import "math"

func closetTarget(words []string, target string, startIndex int) int {
	size := len(words)
	result := math.MaxInt
	for index, word := range words {
		if word == target {
			result = min(result, min(abs2515(index-startIndex), size-abs2515(index-startIndex)))
		}
	}
	if result == math.MaxInt {
		return -1
	}
	return result
}

func abs2515(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
